var entity = require('../entity');
var LogRecord = entity.LogRecord;

exports.saveLog = function(entity, entityId, content, type, callback){
    var log = new LogRecord();
    log.entity = entity;
    log.entityId = entityId;
    log.content = content;
    log.type = type | 'info';
    log.save(function(err, log){
        callback(err, log)
    })
}

exports.pageLogs = function(entity, entityId, pageNo, pageSize, callback){
    var start = (pageNo - 1)*pageSize;
    LogRecord.find({entity: entity, entityId: entityId})
        .skip(start)
        .limit(pageSize)
        .sort({time: -1})
        .exec(function(err, logs){
            callback(err, logs);
    })
}